package com.note.kafka.service;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * <p>【描述】：kafka 消费者</p>
 * <p>【作者】: BeyMax</p>
 * <p>【日期】: 2019-08-29</p>
 **/
@Slf4j
@Service
public class KafkaConsumerServiceImpl implements KafkaConsumerService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());



    /**
     * <p>【描述】：采集任务配置</p>
     * <p>【方法】：sendTaskConfigKafka</p>
     * <p>【参数】: [message]</p>
     * <p>【作者】: BeyMax</p>
     * <p>【日期】: 2019-08-29</p>
     */
    @Override
    public JSONObject getTaskConfigKafka(JSONObject message) {

            return message;

    }

    @Override
    public void listenLinkedInTask(JSONObject parseObject) {
        //处理消息
        //
    }


    public static String getNowDate() {
        //创建SimpleDateFormat对象实例并定义好转换格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // System.out.println("把当前时间转换成字符串：" + sdf.format(new Date()));
        String date = null;
        try {
            // 注意格式需要与上面一致，不然会出现异常
            date = sdf.format(new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("字符串转换成时间:" + date);
        return date;
    }


    /**
     * <p>【描述】：按照日期拼接搜索条件</p>
     * <p>【方法】：spilBean</p>
     * <p>【参数】: [beginTime, endTime, username, datasetName]</p>
     * <p>【作者】: BeyMax</p>
     * <p>【日期】: 2019/12/31</p>
     **/
    private String spilBean(String beginTime, String endTime, String username, String datasetName) {

        String these_words = "{\n" +
                "\"All_of_these_words\": \"\",\n" +
                "\"From_date\": \"2018-5-15\",\n" +
                "\"End_date\": \"2018-7-15\",\n" +
                "\"This_exact_phrase\": \"\",\n" +
                "\"Any_of_ords\": \"\",\n" +
                "\"languages\": \"\",\n" +
                "\"Mentioning_accounts\": \"\",\n" +
                "\"None_words\": \"\",\n" +
                "\"From_accounts\": \"\",\n" +
                "\"Near_place\": \"\",\n" +
                "\"To_accounts\": \"\",\n" +
                "\"hashtags\": \"\"\n" +
                '}';
        JSONObject these_wordsS = (JSONObject) JSONObject.parse(these_words);
        these_wordsS.put("From_date", beginTime.substring(0, 10));
        these_wordsS.put("End_date", endTime.substring(0, 10));
        these_wordsS.put("From_accounts", username);

        return "";

    }

    /**
     * <p>【描述】：判断采集类型</p>
     * <p>【方法】：checkType</p>
     * <p>【参数】: [beginTime, endTime]</p>
     * <p>【作者】: BeyMax</p>
     * <p>【日期】: 2019/12/31</p>
     **/


    public static void main(String[] args) {
        KafkaConsumerService test = new KafkaConsumerServiceImpl();
        JSONObject jo = new JSONObject();
        jo.put("accountName", "zhangsan,lisi");
        // 数据集名称
        jo.put("datasetName", "test");
        // 主帖数量
        jo.put("articleAmount", 100);
        // 评论数量
        jo.put("commentAmount", 200);
        // 关注数量
        jo.put("attentionAmount", 100);
        // 粉丝数量
        jo.put("followAmount", 100);
        // 数据集id
        jo.put("datasetId", 1);
        // 采集类型
        jo.put("spiderType", 1);
        // 用户id
        jo.put("userId", 666);
        // 发帖时间范围
        jo.put("begin_time", "2019-01-01");
        jo.put("end_Time", "2019-12-01");
        test.getTaskConfigKafka(jo);

    }

    /**
     * <p>【描述】：消费LinkedIn任务数据</p>
     * <p>【方法】：listenLinkedInTask</p>
     * <p>【参数】: [parseObject]</p>
     * <p>【作者】: </p>
     * <p>【日期】: 2020/4/30</p>
     **/


}
